package com.sgb.kjwl.viewmodel.transport;

import android.app.Application;
import android.graphics.Color;
import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;

import com.sgb.kjwl.model.entity.self.GoodsSourceDetail;
import com.sgb.kjwl.model.entity.transport.GoodsSourcePlace;
import com.sgb.kjwl.model.entity.transport.SingleItemConstant;
import com.sgb.kjwl.model.entity.transport.SingleItemEntity;
import com.sgb.kjwl.model.entity.transport.TransportOrderEntity;
import com.sgb.kjwl.utils.EntityConversion;
import com.sgb.kjwl.utils.NumberUtil;
import com.swgk.core.util.DateUtils;
import com.swgk.core.util.StringUtil;

import java.util.List;

public class RequireInfoViewModel  extends AndroidViewModel {
    public RequireInfoViewModel(@NonNull Application application) {
        super(application);
    }
    /**
     * 设置货源信息
     */
    public void syncGoodsInfo(List<SingleItemEntity> list, TransportOrderEntity goodsSourcePkace, String orderStatus, boolean isOwner) {
        list.add(new SingleItemEntity(SingleItemConstant.TYPE_ONE,"装车要求",TextUtils.isEmpty(goodsSourcePkace.getloadRequireWords())?"/":goodsSourcePkace.getloadRequireWords()));
        list.add(new SingleItemEntity(SingleItemConstant.TYPE_ONE,"卸车要求",TextUtils.isEmpty(goodsSourcePkace.getUnloadRequireWords())?"/":goodsSourcePkace.getUnloadRequireWords()));
        list.add(new SingleItemEntity(SingleItemConstant.TYPE_ONE,"装车时间", DateUtils.stampToDay5(goodsSourcePkace.getShipmentTime() + "")+(goodsSourcePkace.getShipmentEndTime()==null||goodsSourcePkace.getShipmentEndTime()==0?"":"-"+DateUtils.stampToDay5(goodsSourcePkace.getShipmentEndTime()+""))));
        list.add(new SingleItemEntity(SingleItemConstant.TYPE_ONE,"货物损坏/丢失赔偿约定",TextUtils.isEmpty(goodsSourcePkace.getLostPromise())?"/":goodsSourcePkace.getLostPromise()));
        if (TextUtils.isEmpty(goodsSourcePkace.getPerformanceBond())){
            list.add(new SingleItemEntity(SingleItemConstant.TYPE_ONE,"履约保证金",TextUtils.isEmpty(goodsSourcePkace.getPerformanceBond())?"/":NumberUtil.trim0(goodsSourcePkace.getPerformanceBond())+"元"));
        }else {
            list.add(new SingleItemEntity(SingleItemConstant.TYPE_TWO,"履约保证金",TextUtils.isEmpty(goodsSourcePkace.getPerformanceBond())?"/":NumberUtil.trim0(goodsSourcePkace.getPerformanceBond())+"元",Color.parseColor("#FF6600")));
        }
        list.add(new SingleItemEntity(SingleItemConstant.TYPE_TWO,"信息费",goodsSourcePkace.getMessagePrice(),Color.parseColor("#FF6600")));
        list.add(new SingleItemEntity(SingleItemConstant.TYPE_ONE,"逾期装货或到货违约责任约定",TextUtils.isEmpty(goodsSourcePkace.getOverduePromise())?"/":goodsSourcePkace.getOverduePromise()));
        list.add(new SingleItemEntity(SingleItemConstant.TYPE_ONE,"其他约定",TextUtils.isEmpty(goodsSourcePkace.getOtherPromise())?"/":goodsSourcePkace.getOtherPromise()));
        if(isOwner){
            if (goodsSourcePkace.status!=1) {
                list.add(new SingleItemEntity(SingleItemConstant.TYPE_FOUR));
                list.add(new SingleItemEntity(SingleItemConstant.TYPE_ONE, "发货单位", TextUtils.isEmpty(goodsSourcePkace.getSendGoodsUnit()) ? "/" : goodsSourcePkace.getSendGoodsUnit()));
                list.add(new SingleItemEntity(SingleItemConstant.TYPE_ONE, "联系人", TextUtils.isEmpty(goodsSourcePkace.getSendPeople()) ? "/" : goodsSourcePkace.getSendPeople()));
                list.add(new SingleItemEntity(SingleItemConstant.TYPE_THREE, "联系电话", TextUtils.isEmpty(goodsSourcePkace.getSendPhone()) ? "/" : goodsSourcePkace.getSendPhone()));
                list.add(new SingleItemEntity(SingleItemConstant.TYPE_FOUR));
                list.add(new SingleItemEntity(SingleItemConstant.TYPE_ONE, "收货单位", TextUtils.isEmpty(goodsSourcePkace.getReceiveGoodsUnit()) ? "/" : goodsSourcePkace.getReceiveGoodsUnit()));
                list.add(new SingleItemEntity(SingleItemConstant.TYPE_ONE, "联系人", TextUtils.isEmpty(goodsSourcePkace.getReceptionPeople()) ? "/" : goodsSourcePkace.getReceptionPeople()));
                list.add(new SingleItemEntity(SingleItemConstant.TYPE_THREE, "联系电话", TextUtils.isEmpty(goodsSourcePkace.getReceptionPhone()) ? "/" : goodsSourcePkace.getReceptionPhone()));
            }
        } else if(!isOwner&&!orderStatus.equals("0")) {//司机订单 待确认
            list.add(new SingleItemEntity(SingleItemConstant.TYPE_FOUR));
            list.add(new SingleItemEntity(SingleItemConstant.TYPE_ONE, "发货单位", TextUtils.isEmpty(goodsSourcePkace.getSendGoodsUnit()) ? "/" : goodsSourcePkace.getSendGoodsUnit()));
            list.add(new SingleItemEntity(SingleItemConstant.TYPE_ONE, "联系人", TextUtils.isEmpty(goodsSourcePkace.getSendPeople()) ? "/" : goodsSourcePkace.getSendPeople()));
            list.add(new SingleItemEntity(SingleItemConstant.TYPE_THREE, "联系电话", TextUtils.isEmpty(goodsSourcePkace.getSendPhone()) ? "/" : goodsSourcePkace.getSendPhone()));
            list.add(new SingleItemEntity(SingleItemConstant.TYPE_FOUR));
            list.add(new SingleItemEntity(SingleItemConstant.TYPE_ONE, "收货单位", TextUtils.isEmpty(goodsSourcePkace.getReceiveGoodsUnit()) ? "/" : goodsSourcePkace.getReceiveGoodsUnit()));
            list.add(new SingleItemEntity(SingleItemConstant.TYPE_ONE, "联系人", TextUtils.isEmpty(goodsSourcePkace.getReceptionPeople()) ? "/" : goodsSourcePkace.getReceptionPeople()));
            list.add(new SingleItemEntity(SingleItemConstant.TYPE_THREE, "联系电话", TextUtils.isEmpty(goodsSourcePkace.getReceptionPhone()) ? "/" : goodsSourcePkace.getReceptionPhone()));
        }

    }
}
